﻿using System;
using System.Data;
using System.Data.Common;
using StandardDAC.Base;
using System.Collections.Generic;

namespace StandardDAC {
    /// <summary>
    /// Defines methods for the base controller to call to create new commands, connections, etc.
    /// </summary>
    public interface IDBTypeAdapter {
        /// <summary>
        /// Creates a new DbCommand object
        /// </summary>
        /// <param name="commandText"></param>
        /// <param name="connection"></param>
        /// <returns></returns>
        DbCommand NewCommand(string commandText, DbConnection connection, ConnOrTranInfo conn);
        /// <summary>
        /// Creates a new connection to the database. (Does not open the connection)
        /// </summary>
        /// <param name="conn"></param>
        /// <returns></returns>
        DbConnection NewConnection(ConnOrTranInfo conn);
        /// <summary>
        /// Creates a new adapter to use over the given command
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        DbDataAdapter NewAdapter(DbCommand command);
        /// <summary>
        /// Adds parameter of the given type and name to the command object
        /// </summary>
        /// <param name="name"></param>
        /// <param name="dbType"></param>
        /// <param name="command"></param>
        /// <returns></returns>
        DbParameter AddNewParameter(string name, object dbType, DbCommand command);
        /// <summary>
        /// Adds a parameter, ignoring is type, with a null value. 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="command"></param>
        /// <returns></returns>
        DbParameter AddNewNullParameter(string name, DbCommand command);
        /// <summary>
        /// Adds an existing parameter back on to the command
        /// </summary>
        /// <param name="param"></param>
        /// <param name="command"></param>
        /// <returns></returns>
        DbParameter AddExistingParameter(DbParameter param, DbCommand command);
        /// <summary>
        /// Add your @ or whatever to the front of a column name to get the parameter name
        /// </summary>
        /// <param name="columnName"></param>
        /// <returns></returns>
        string ConvertNameToParam(string columnName);
        /// <summary>
        /// DBController runs this before every execute. OleDb and ODBC need to make sure that StoredProcedures
        /// are called in this way: "call Subzero.UploadFAI (?,?,?,?)". It adds the call and the number of ? based
        /// on the number of parameters that you're passing in. SqlClient and Oracle don't do anything here.
        /// </summary>
        /// <param name="command"></param>
        void PreExecute(DbCommand command);
        /// <summary>
        /// This gets run if you use the methods based on the DbColumn. OleDb and ODBC connections do not have named
        /// parameters, so it is important that the parameters are in the specified sort order. SqlClient and Oracle 
        /// don't do anything here.
        /// </summary>
        /// <param name="parametersToSort"></param>
        /// <param name="cmd"></param>
        void SortParametersIfNeeded(Dictionary<string, KeyValuePair<int, DBColumn>> parametersToSort, DbCommand cmd);

        void AddOutputCursorIfNeeded(DbCommand cmd, Type type);
    }
}
